home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DViewCentral.cpp < prev    next >
Encoding:
Text File  |  1996-07-05  |  2.6 KB  |  120 lines  |  [TEXT/R*ch]

  1. // DViewCentral.cp
  2. // d.g.gilbert
  3.  
  4.  
  5.  
  6. #include "DViewCentral.h"
  7. #include "DList.h"
  8. #include "Dvibrant.h"
  9.  
  10.  
  11. DViewCentral *gViewCentral = NULL;
  12.  
  13. // original use for DViewCentral class was to link nlmObjects to DViews
  14. // that need may be gone.  Other use:
  15. // find any view given a view id -- is that useful to handle view tasks?
  16. // still likely need this to use MenuItem views...
  17. //
  18.  
  19. //class DViewCentral : public DObject
  20.  
  21. DViewCentral::DViewCentral() 
  22. {
  23.     fViewRegistry= new DList();
  24. }
  25.  
  26.  
  27. DViewCentral::~DViewCentral() 
  28. {
  29.     fViewRegistry->FreeAllObjects();  
  30.     fViewRegistry->suicide();   // delete  
  31. }
  32.         
  33. void DViewCentral::RegisterView(DView* theView) 
  34. {
  35.         // 20Jan94 -- looks like we only use gViewCentral for kMenu and kMenuItem kinds !!!
  36.         // make this a bit saner by screening out all others?? 
  37.         // rename viewcentral to menucentral??
  38.     if (theView && theView->Id() 
  39.      && (theView->fKind == kMenu || theView->fKind == kMenuItem)) {
  40.         theView->newOwner(); // so we can suicide it and caller can suicide it;
  41.         fViewRegistry->InsertLast(theView);
  42.         }
  43. }
  44.  
  45. void DViewCentral::RegisterView(long id, Nlm_Handle nlmObject, short kind, DTaskMaster* itsSource) 
  46. {
  47.     if (id) {
  48.       DView* aview= new DView(id, nlmObject, kind, itsSource);
  49.       if (aview->GetOwnerCount() > 1) aview->suicide(); // new & RegisterView() both bumped counter
  50.       //fViewRegistry->InsertLast(); << !! new DView() calls this->RegisterView(newview)
  51.       } 
  52. }
  53.     
  54. void DViewCentral::RemoveView(long id) 
  55. {
  56.     if (id) {
  57.         long i, n= fViewRegistry->GetSize();
  58.         for (i= n-1; i>= 0; i--) {
  59.             DView* aview= (DView*)fViewRegistry->At(i);
  60.             if (aview->Id() == id) {
  61.                 fViewRegistry->AtDelete(i);
  62.                 aview->suicide();
  63.                 break;
  64.                 }
  65.             }        
  66.         }
  67. }
  68.  
  69. DView* DViewCentral::GetView(long id) 
  70. {
  71.     if (id) {
  72.         long i, n= fViewRegistry->GetSize();
  73.         for (i= 0; i<n; i++) {
  74.             DView* aview= (DView*)fViewRegistry->At(i);
  75.             if (aview->Id() == id) return aview;
  76.             }        
  77.         }
  78.     return NULL;
  79. }
  80.  
  81.  
  82.  
  83. void DViewCentral::DoViewMethod(long id, ViewMethod vmethod) 
  84. {
  85.     if (id) {
  86.         long i, n= fViewRegistry->GetSize();
  87.         for (i= 0; i<n; i++) {
  88.             DView* aview= (DView*)fViewRegistry->At(i);
  89.             if (aview && aview->Id() == id) {
  90.                 (aview->*vmethod)();
  91.                 return;
  92.                 }
  93.             }        
  94.         }
  95. }
  96.  
  97.  
  98. DView*  DViewCentral::NlmItem2View(Nlm_Handle nlmObject)  
  99. {
  100.     long i, n= fViewRegistry->GetSize();
  101.     for (i= 0; i<n; i++) {
  102.         DView* aview= (DView*)fViewRegistry->At(i);
  103.         if (aview->fNlmObject == nlmObject) return aview;
  104.         }        
  105.     return NULL;
  106. }
  107.  
  108. Nlm_Handle DViewCentral::View2NlmItem(long id)  
  109. {
  110.     if (id) {
  111.     long i, n= fViewRegistry->GetSize();
  112.     for (i= 0; i<n; i++) {
  113.         DView* aview= (DView*)fViewRegistry->At(i);
  114.         if (aview->Id() == id) return aview->fNlmObject;
  115.         }        
  116.         }
  117.     return NULL;
  118. }
  119.  
  120.